﻿using Gnivc.CarDealership.Api.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using static Gnivc.CarDealership.Api.Infrastructure.Persistence.PersistenceConstants;

namespace Gnivc.CarDealership.Api.Infrastructure.Persistence.Configurations;

public class ModelConfiguration : IEntityTypeConfiguration<Model>
{
    public void Configure(EntityTypeBuilder<Model> builder)
    {
        builder.ToTable(TableNames.Models, SchemaNames.Retail)
            .HasKey(x => x.Id);

        builder.Property(x => x.Name)
            .HasMaxLength(255);

        builder.HasOne(x => x.Brand)
            .WithMany(x => x.Models)
            .HasForeignKey(x => x.BrandId);
    }
}
